package com.hccl.controller;

import org.json.JSONObject;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;

/**
 * Created by sunjia on 2018/7/10.
 */

@RestController
@RequestMapping("/")
public class ClusteringController {

    public static BlockingQueue<JSONObject> blockingQueue = new ArrayBlockingQueue<>(100);  //初始化队列,容量100

    @RequestMapping(value = "/clustering", method = RequestMethod.POST)
    public ResponseEntity<Object> clustering(HttpServletRequest request,
                                             @RequestBody(required = true) String jsonStr) throws Exception {

        JSONObject injson = new JSONObject(jsonStr);
        blockingQueue.add(injson);
        JSONObject json = new JSONObject();
        json.put("code", "0");
        json.put("message", "收到聚类请求");
        return new ResponseEntity<Object>(json.toString(), HttpStatus.OK);

    }
}
